package com.zh.note.huawei.onehundred.数据分类;

import java.util.Scanner;

/**
 * https://dream.blog.csdn.net/article/details/129364908
 */
public class Main {
    public static void main(String[] args) {

        // System.out.println(0x01010101);
        Scanner sc = new Scanner(System.in);
        // String line = sc.nextLine();
        String line = "3 4 256 257 258 259 260 261 262 263 264 265";
        String[] values = line.split(" ");
        int c = Integer.parseInt(values[0]);
        int b = Integer.parseInt(values[1]);
        int[] arr = new int[b - 1];
        for (int i = 2; i < values.length; i++) {
            int res = solution(Integer.parseInt(values[i])) % b;
            if (res < c) {
                arr[res]++;
            }
        }
        //找到数组中最大值
        int result = -1;
        for (int i = 0; i < arr.length; i++) {
            result = Math.max(result, arr[i]);
        }
        System.out.println(result);
    }

    private static int solution(int num) {
        String str = Integer.toBinaryString(num);
        int sum = 0;
        while (str.length() > 8) {
            String temp = str.substring(str.length() - 8);
            sum += Integer.parseInt(temp);
            str = str.substring(0, str.length() - 8);
        }
        sum += Integer.parseInt(str);
        return sum;
    }
}
